package com.mdd.admin.tools;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.Date;

/**
 * 时间计算工具类
 */
public class TimeUtils {
    public static void main(String[] args) {

        DateTime dateTime = DateUtil.beginOfDay(new Date());
        Instant instant = dateTime.toInstant();
        LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
        localDateTime = localDateTime.plusDays(1);
        LocalDateTime startLocalDateTime = null;
        for (int i = 0; i <6; i++) {
            System.out.println("------------第" + (i + 1) + "期租赁账单----------------------------------------");
            if (i == 0) {
                startLocalDateTime = localDateTime.plusMonths(i);
            }
            ZonedDateTime startZonedDateTime = startLocalDateTime.atZone(ZoneId.systemDefault());
            Instant startInstant = startZonedDateTime.toInstant();
            Date startDate = Date.from(startInstant);
            String startTime = DateUtil.format(DateUtil.beginOfDay(startDate), "yyyy-MM-dd HH:mm:ss");
            System.out.println("还款开始时间：" + startTime);
            LocalDateTime endLocalDateTime = localDateTime.plusMonths(i + 1);
            ZonedDateTime endZonedDateTime = endLocalDateTime.atZone(ZoneId.systemDefault());
            Instant endInstant = endZonedDateTime.toInstant();
            Date endDate = Date.from(endInstant);
            String endTime = DateUtil.format(DateUtil.endOfDay(endDate), "yyyy-MM-dd HH:mm:ss");
            System.out.println("还款结束时间：" + endTime);
            startLocalDateTime = endLocalDateTime;
        }
    }
}
